package com.lecyon.farm.vo.view;

import com.lecyon.farm.common.constant.FarmSysConstant;
import com.lecyon.farm.util.StringHelper;
import com.lecyon.farm.util.ValidateUtils;
import com.lecyon.farm.vo.base.BaseViewVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @author YaoZheng
 * @since 2020-04-02
 */
@Data
@ApiModel("农机当季作业详情")
public class FmWorkDetailsVo extends BaseViewVo {

    @ApiModelProperty(name = "id", value = "编号")
    private String id;

    @ApiModelProperty(name = "workSerial", value = "一次作业流水号")
    private String workSerial;

    @ApiModelProperty(name = "carId", value = "主机号")
    private String carId;

    @ApiModelProperty(name = "carOwner", value = "车主")
    private String carOwner;

    @ApiModelProperty(name = "carOwnerPhone", value = "车主电话")
    private String carOwnerPhone;

    @ApiModelProperty(name = "toolId", value = "农具号")
    private String toolId;

    @ApiModelProperty(name = "workDate", value = "作业日期")
    private LocalDateTime workDate;

    @ApiModelProperty(name = "workStarttime", value = "作业开始时间")
    private LocalDateTime workStarttime;

    @ApiModelProperty(name = "workEndtime", value = "作业结束时间")
    private LocalDateTime workEndtime;

    @ApiModelProperty(name = "avgDepth", value = "平均深度")
    private String avgDepth;

    @ApiModelProperty(name = "distance", value = "里程")
    private String distance;

    @ApiModelProperty(name = "gps", value = "gps坐标点集合")
    private String gps;

    @ApiModelProperty(name = "landname", value = "地块名")
    private String landname;

    @ApiModelProperty(name = "workLandarea", value = "作业面积(多边形)")
    private String workLandarea;

    @ApiModelProperty(name = "submitLandarea", value = "提交面积")
    private String submitLandarea;

    @ApiModelProperty(name = "workDistanceArea", value = "作业面积(距离)")
    private String workDistanceArea;

    @ApiModelProperty(name = "qualifiedLandarea", value = "合格面积")
    private String qualifiedLandarea;

    @ApiModelProperty(name = "passRate", value = "合格率")
    private String passRate;

    @ApiModelProperty(name = "passRateA", value = "合格率a")
    private String passRateA;

    @ApiModelProperty(name = "passRateB", value = "合格率b")
    private String passRateB;

    @ApiModelProperty(name = "overlapRate", value = "重叠率")
    private String overlapRate;

    @ApiModelProperty(name = "width", value = "幅宽")
    private String width;

    @ApiModelProperty(name = "flag", value = "计入补助标识")
    private String flag;

    @ApiModelProperty(name = "type", value = "作业类型")
    private String type;

    @ApiModelProperty(name = "type_dict", value = "耕种类型Dict")
    private String typeDict;

    @ApiModelProperty(name = "serialNo", value = "编号")
    private String serialNo;

    @ApiModelProperty(name = "location", value = "编号")
    private String location;

    @ApiModelProperty(name = "locationCity", value = "编号")
    private String locationCity;

    @ApiModelProperty(name = "locationDistrict", value = "编号")
    private String locationDistrict;

    @ApiModelProperty(name = "locationTownship", value = "编号")
    private String locationTownship;

    @ApiModelProperty(name = "userCode", value = "用户编号")
    private String userCode;

    @ApiModelProperty(name = "totalFlow", value = "植保流量")
    private String totalFlow;

    @ApiModelProperty(name = "identify", value = "新旧平台标识")
    private String identify;

    @ApiModelProperty(name = "seed", value = "播种数")
    private String seed;

    @ApiModelProperty(name = "seedPerMu", value = "每亩播种数")
    private String seedPerMu;

    public String getSeedPerMu() {
        if (ValidateUtils.isNullOrEmpty(seedPerMu)) {
            if (StringHelper.isNotEmpty(seed) && StringHelper.isNotEmpty(workLandarea)) {
                // 每亩播种数 = 播种数 / 作业面积
                double seedDouble = Double.parseDouble(seed);
                double workLandareaDouble = Double.parseDouble(workLandarea);
                double seedPerMuDouble;
                if (0 == workLandareaDouble) {
                    seedPerMuDouble = 0;
                } else {
                    seedPerMuDouble = seedDouble / workLandareaDouble;
                }
                seedPerMu = String.format("%.2f", seedPerMuDouble);
            }
        }
        return seedPerMu;
    }

    public String getTypeDict() {
        if (StringHelper.isNotEmpty(type)) {
            boolean flag = FarmSysConstant.SYS_JOB_TYPE_MAP.containsKey(type);
            if (flag) {
                typeDict = FarmSysConstant.SYS_JOB_TYPE_MAP.get(type);
                if (StringHelper.isNotEmpty(typeDict)) {
                    return typeDict;
                }
            }
        }
        return typeDict;
    }
}
